package com.buddies.lottery.ui.pay;

import com.buddies.lottery.base.BasePresenter;
import com.buddies.lottery.common.ConfigManager;
import com.buddies.lottery.data.BaseObserver;
import com.buddies.lottery.data.DataManager;
import com.buddies.lottery.data.resp.PayResponse;
import com.buddies.lottery.data.resp.PayResultResponse;

/**
 * Created by xuliang on 2018/2/28.
 */

public class PayPresenter extends BasePresenter<PayContract.View> implements PayContract.Presenter {

    public PayPresenter(PayContract.View view) {
        super(view);
    }

    @Override
    public void postPay(String payType, String money) {
        addSubscription(DataManager.getInstance().getUserRepo().postPay(payType, money), new BaseObserver<PayResultResponse>() {
            @Override
            public void onNext(PayResultResponse response) {
                mView.onPaySuccess(response);
            }

            @Override
            public void onError(Throwable e) {
               mView.onError(e);
            }
        });
    }

    @Override
    public void loadPayQrcode() {
        addSubscription(DataManager.getInstance().getUserRepo().getPayQrcode(), new BaseObserver<PayResponse>() {
            @Override
            public void onNext(PayResponse response) {
                ConfigManager.getInstance().setBalance(response.balance);
                mView.onPayQrcodeLoaded(response);
            }

            @Override
            public void onError(Throwable e) {
                mView.onError(e);
            }
        });
    }
}
